package com.heima.kafka.listener;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.heima.kafka.dto.UserDto;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class HelloListener {
    @KafkaListener(topics = "kafkaTest")
    public void onMessage(String message){
        if (ObjectUtil.isNotEmpty(message)) {
            System.out.println("接收到消息：" + message);
        }
    }
    @KafkaListener(topics = "kafkaTestUser")
    public void onUserMessage(String message){
        if (ObjectUtil.isNotEmpty(message)) {
            System.out.println("接收到消息：" + message);
            System.out.println("userDto：" + JSONUtil.toBean(message, UserDto.class));
        }
    }
}
